#include "ALERobert.h"
//#include <opencv2/opencv.hpp>
//#include <opencv2/imgproc/types_c.h>

CALERobert::CALERobert()
{
}

CALERobert::CALERobert(CALStepItem* pStepItem)
{
	m_pStepItem = pStepItem;
}

CALERobert::~CALERobert()
{
}

void CALERobert::test()
{

}

void CALERobert::convert()
{
	if (m_pStepItem == NULL) return;

	try
	{
		CALSIERobert* pStepItem = (CALSIERobert*)m_pStepItem;

		m_dstMat = roberts(m_srcMat);

		SetDstType(AL_DST_Mat_One);
	}
	catch (...)
	{

	}
}

void CALERobert::convert(const Mat &src, Mat &dst)
{

}

Mat CALERobert::roberts(Mat srcImage)
{
	Mat dstImage = srcImage.clone();
	int nRows = dstImage.rows;
	int nCols = dstImage.cols;
	for (int i = 0; i < nRows - 1; i++)
	{
		for (int j = 0; j < nCols - 1; j++)
		{
			int t1 = (srcImage.at<uchar>(i, j) -
				srcImage.at<uchar>(i + 1, j + 1)) *
				(srcImage.at<uchar>(i, j) -
					srcImage.at<uchar>(i + 1, j + 1));
			int t2 = (srcImage.at<uchar>(i + 1, j) -
				srcImage.at<uchar>(i, j + 1)) *
				(srcImage.at<uchar>(i + 1, j) -
					srcImage.at<uchar>(i, j + 1));
			dstImage.at<uchar>(i, j) = (uchar)sqrt(t1 + t2);

		}
	}
	return dstImage;
}

